<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>forEach</title>
<style type="text/css">
	body {background-color: white; color: black; font-family:sans-serif; font-size:medium;}
	a:link {color: #3300ff;}
	a:visited {color: #663399;}
	a:hover {color:#0099ff;}
	a:active {color: #0066cc;}
	a.button {text-decoration:none;}
	
	table.nav  {background-color: #dbddff;}
	table.body {margin-top:2ex; margin-bottom:2ex;}
	table.programlistingindent {margin-left:32px;}
	
	img { margin-bottom:0px; margin-top:0px;}
	tt {margin-left:0.5em; margin-right:0.5em; font-weight:lighter;}
	
	p {margin-top:0ex;}
	p.synopsis {margin-left:32px;}
	p.programlistingindent {margin-left:32px;}
	p.citetitle {margin-left:2em;}
	
	ul ul {list-style-type:square;}
	ul li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	ol li p {margin-top:0ex; margin-bottom:.5ex; padding:0}
	
	h1.reftitle {color:#a90000;}
	h1.reftitle {font-size:3.7ex; margin-top:0; margin-bottom:0; font-weight:bold}
	h1.title {color:black; font-size:4ex; margin-top:1ex; font-weight:bold}
	h2.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:3ex}
	h3.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h4.title {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex}
	h2 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2.5ex}
	h3 {color:#bd0000; margin-top:1ex; margin-bottom:.9ex; font-weight:bold; font-size:2ex} 
	
	pre.programlisting {margin-left:32px;}
	pre.synopsis {margin-left:32px;}
	
	
	.categorytitle {margin-top:8px; padding-top:0px;}
	.categorylist {background-color: #e1e6f2;}
 	</style>
</head>
<body>
<a name="top_of_page"></a><p style="font-size:1px;"></p>
<h1 class="reftitle">forEach</h1>
<h2>Purpose</h2>
<p>Applies a given function to each element of in an array of sets.</p>
<h2>Syntax</h2>
<pre class="synopsis">A = obj.forEach(@myfun)</pre>
<pre class="synopsis">A = obj.forEach(@(x) myfun(x))</pre>
<pre class="synopsis">A = obj.forEach(@(x) x.myfun)</pre>
<h2>Description</h2>
<p></p>
             The method <tt>forEach</tt> is an overloaded method of standard
             <tt>arrayfun</tt> or <tt>cellfun</tt> that applies to arrays of sets.			 
             To apply method MYFUN to all elements of the array of
			 objects OBJ, you can use any of the following ways:<br><br>
             
      <ul>
             
         <li>
            <tt>obj.forEach(@myfun)</tt>
         </li>
             
         <li>
            <tt>obj.forEach(@(x) myfun(x))</tt>
         </li>
             
         <li>
            <tt>obj.forEach(@(x) x.myfun)</tt>
         </li>
             
      </ul>
                 
             Note that <tt>forEach</tt> will not return any outputs if not asked
			 to. Outputs can be requested as well: <br><br>

             
      <tt>[A, B, C] = obj.forEach(@myfun)</tt>
			 
			 If MYFUN generates all its outputs as scalars, then A, B, and
			 C will be arrays with as many elements as there are elements
			 in the array OBJ.  
             
			 If outputs generated by MYFUN have different sizes for
			 different elements of OBJ, then you must set the
			 "UniformOutput" option to false:<br><br>             
             
             
      <tt>[A, B, C] = obj.forEach(@myfun, 'UniformOutput', false) </tt> 
             
             In this case <tt>A</tt>, <tt>B</tt>, and <tt>C</tt> will be cell arrays, with 
             A{i}, B{i} and C{i} containing the output of MYFUN applied to the
			 i-th element of OBJ.  

             In short, the <tt>forEach</tt> method works exactly as <tt>arrayfun</tt>
             and <tt>cellfun</tt>, hence see "help arrayfun" for a more throught
			 description.
    <h2>Input Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>@myfun</tt></td>
<td>
<p></p> A handle to a function that is to be applied to each element in the array of sets for object <tt>obj</tt>.
        <p>
	    		Class: <tt>function_handle</tt></p>
</td>
</tr></tbody>
</table>
<h2>Output Arguments</h2>
<table cellspacing="0" class="body" cellpadding="4" border="0" width="100%">
<colgroup>
<col width="31%">
<col width="69%">
</colgroup>
<tbody><tr valign="top">
<td><tt>A</tt></td>
<td>
<p></p> Array or cell array of outputs returned by function <tt>@myfun</tt> that correspond to individual outputs 
        from the array of sets <tt>obj</tt>. <p>
	    		Class: <tt></tt></p>
</td>
</tr></tbody>
</table>
<h2>Example(s)</h2>
<h3>Example 
				1</h3> Create array of 5 random polyhedra <pre class="programlisting"> for i=1:5; P(i)=ExamplePoly.randVrep; end </pre>
<pre class="programlisting"></pre> For each polyhedron in the array execute the function <tt>outerApprox</tt> 
      <pre class="programlisting"> B = P.forEach(@outerApprox) </pre>
<pre class="programlisting">Array of 5 polyhedra.
</pre> In B we have computed the outer bounding boxes for each polyhedron in the array. It is the same
            results if asked<pre class="programlisting"> Bnew = P.outerApprox </pre>
<pre class="programlisting">Array of 5 polyhedra.
</pre>
<h3>Example 
				2</h3> Create two unions of polyhedra in different dimensions<pre class="programlisting"> U(1) = PolyUnion([ExamplePoly.randVrep;ExamplePoly.randVrep]); </pre>
<pre class="programlisting"></pre>
<pre class="programlisting"> U(2) = PolyUnion([ExamplePoly.randVrep('d',3);ExamplePoly.randVrep('d',3)]); </pre>
<pre class="programlisting"></pre> For each polyunion in the array extract the convexity property that is computed by <tt>isConvex</tt> method.<pre class="programlisting"> ts = U.forEach(@isConvex)</pre>
<pre class="programlisting">
ts =

     0     0

</pre> The same result can be obtained by <pre class="programlisting"> tn = U.isConvex </pre>
<pre class="programlisting">
tn =

     0     0

</pre>
<h2>See Also</h2>
<a href="../../modules/geometry/sets/@Polyhedron/polyhedron.html">polyhedron</a>, <a href="../../modules/geometry/sets/@ConvexSet/convexset.html">convexset</a><p></p>
<table class="nav" summary="Navigation aid" border="0" width="100%" cellpadding="0" cellspacing="0"><tr valign="top">
<td align="left" width="20">
<a href="../../../mpt.html" class="button">&#9664;</a>  </td>
<td align="left">mpt</td>
<td>  </td>
<td align="right">iterablebehavior</td>
<td align="right" width="20"><a href="iterablebehavior.html" class="button">&#9654;</a></td>
</tr></table>
<br><p>©  <b>2003-2013</b>     Michal Kvasnica: STU Bratislava,    <a href="mailto:michal.kvasnica@stuba.sk">michal.kvasnica@stuba.sk</a></p>
<p>©  <b>2010-2013</b>     Martin Herceg: ETH Zurich,    <a href="mailto:herceg@control.ee.ethz.ch">herceg@control.ee.ethz.ch</a></p>
</body>
</html>
